// JavaScript Document


function createDOMDocument(strNamespaceURI, strRootTagName) {
	var objDOM;
	if(!MSIE){
		objDOM = document.implementation.createDocument(strNamespaceURI, strRootTagName, null);
	}else{
		var STR_ACTIVEX='Microsoft.XMLDOM';
		objDOM = new ActiveXObject(STR_ACTIVEX);
		//if there is a root tag name, we need to preload the DOM
		if (strRootTagName) {
		   //If there is both a namespace and root tag name, then
		   //create an artifical namespace reference and load the XML.
		   if (strNamespaceURI) {
			  objDOM.loadXML("<a0:" + strRootTagName + "xmlns:a0=\"" +  strNamespaceURI + "\" />");
		   } else {
			  objDOM.loadXML('<' + strRootTagName + '/>');
		   }
		}
	}
	return objDOM;
}

function xmlLoader(){
	var doc;
	try{
		if(!MSIE){
			doc=new XMLHttpRequest();
			doc.load=function(url){
				this.open("GET",url,true);
				if(!MSIE){
					this.overrideMimeType('text/xml');
				}
				this.ignoreWhitespace=true;
				this.send(null);
			}
		}else{
			doc = new ActiveXObject("Microsoft.XMLDOM");
			doc.validateOnParse = false;
			doc.async = true;
			doc.preserveWhiteSpace = false;
		}
	}
	catch(err){
	}
	this.doc=doc;
	var tmp=this;
	this.load=function(url){
		if(MSIE){
			tmp.doc.onreadystatechange=function(){
				if(doc.readyState==4){
					/*if(MSIE7){
						tmp.xmlLoaded=doc.responseXML;
					}else{*/
						if(doc.xml){
							tmp.textLoaded=doc.xml;
						}else{
							function gettext(node){
								if(node && node.nodeName.indexOf("#")>=0){
									return node.text;
								}else if(!node){
									return "";
								}
								var txt='<'+node.nodeName+' ';
								if(node.attributes){
									for(var i=0;i<node.attributes.length;i++){
										if(node.attributes[i]){
											txt+=node.attributes[i].name+'="'+node.attributes[i].value+'" ';
										}
									}
								}
								if(node.childNodes.length>0){
									txt+='>';
									for(var i=0;i<node.childNodes.length;i++){
										txt+=gettext(node.childNodes[i]);
									}
								}else{
									txt+=' />';
								}
								return txt;
							}
							tmp.textLoaded=gettext(doc.childNodes[0]);
						}
						tmp.xmlLoaded=doc.lastChild;
					//}
					if(showXmlError(tmp.xmlLoaded)){return;}
					tmp.onload(tmp.xmlLoaded);
				}
			}
		}else{
			this.doc.parentObject=this;
			this.doc.onload=function(){
				this.parentObject.textLoaded=this.responseText;
				this.parentObject.xmlLoaded=this.responseXML;
				if(showXmlError(tmp.xmlLoaded)){return;}
				this.parentObject.onload(this.parentObject.xmlLoaded.firstChild);
			}
		}
		this.doc.load(url);
	}
	this.loadString=function(xmlString){
		var xmlData; 
		if(MSIE){
			xmlData = new ActiveXObject("Microsoft.XMLDOM"); 
			xmlData.async="false"; 
			xmlData.loadXML(xmlString); 
		}else{ 
			var parser = new DOMParser(); 
			xmlData = parser.parseFromString(xmlString,"text/xml"); 
		}
		return xmlData;
	}
	this.onload=function(xmlLoaded){}
}





function getXMLRoot(sXmlResult){
	if (MSIE){
		return sXmlResult.documentElement;
	}else{
 		return sXmlResult.responseXML.childNodes[0];
	}
}

function showXmlError(xml){
	if(xml && xml.firstChild && xml.firstChild.nodeName.toUpperCase()=="EXCEPTION"){
		return true;
	}
	return false;
}